package com.certification.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.entity.CorrectImprove;
import com.certification.vo.CorrectImproveVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * @author copa
 * @createDate 2022-03-30 22:25
 * @function
 */
@Repository
public interface CorrectImproveMapper extends BaseMapper<CorrectImprove> {

    @Select("SELECT pse.first_level_point firstLevelPoint, pse.second_level_point secondLevelPoint, pse.expert_advice improveMethod, IFNULL(pse.correct_status,0) correctStatus, " +
            "pse.correct_explain correctExplain, pse.id id, pse.correct_cert_attachment_id correctCertAttachmentId  " +
            "FROM certification c   " +
            "JOIN profession_self_evaluation pse ON c.id = pse.cert_id   " +
            "WHERE ((c.cert_stage = 3 AND c.cert_status = 2) OR (c.cert_stage = 5 AND c.cert_status < 2)) AND c.principal_id = #{userId} AND pse.id = #{proId}   " +
            "ORDER BY c.id LIMIT 1")
    CorrectImproveVO selectImprove(@Param("proId") Integer proId, @Param("userId") Integer userId);

    @Select("SELECT pse.first_level_point firstLevelPoint, pse.second_level_point secondLevelPoint, pse.expert_advice improveMethod, IFNULL(pse.correct_status,0) correctStatus, " +
            "pse.correct_explain correctExplain, pse.id id, pse.correct_cert_attachment_id correctCertAttachmentId " +
            "FROM certification c   " +
            "JOIN profession_self_evaluation pse ON c.id = pse.cert_id   " +
            "WHERE ((c.cert_stage = 3 AND c.cert_status = 2) OR (c.cert_stage = 5 AND c.cert_status < 2)) AND c.principal_id = #{userId} AND c.id = #{certId} " +
            "ORDER BY c.id DESC ")
    IPage<CorrectImproveVO> selectImprovePage(@Param("userId") Integer userId,
                                              @Param("certId") Integer certId,
                                              Page<CorrectImproveVO> page);
}
